// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
// import 'lib-flexible'

import Vue from 'vue';
import { onRestTableCellWidth, onRestsearchLabelWidth, onRestTreeTableCellWidth } from './util/tableCellWidth'
// import './util/rem'
import ViewUI from 'view-design';
import 'view-design/dist/styles/iview.css';
import '../my_theme/index.less';
import App from './App';
import { router } from './router/index';
import store from './store';
import i18n from '@/locale';
import { getRequest, postRequest, putRequest, postBodyRequest, getNoAuthRequest, postNoAuthRequest, importRequest } from '@/libs/axios';
import { setStore, getStore, removeStore } from '@/libs/storage';
import { format } from 'date-fns';
import util from '@/libs/util';
import hasPermission from '@/libs/hasPermission';
import hasRole from '@/libs/hasRole';
import iviewArea from '@/views/my-components/iview-area';
import XIcon from '@/views/my-components/xboot/x-icon';
import VueLazyload from 'vue-lazyload';
import VueClipboard from 'vue-clipboard2';
import VueApexCharts from 'vue-apexcharts';
import './assets/iconfont/iconfont.css';
import '@/styles/public.css';
import '@/styles/card.css';
import '@babel/polyfill';
import { hasPerm, hasR } from '@/libs/permission';
// import { Message } from 'view-design'
import SlideVerify from 'vue-monoplasty-slide-verify';
//引入自适应布局插件
import 'amfe-flexible';
import 'vue-task-node/dist/css/vnode.css';
import './assets/iconfont/iconfont.css';
//初始化样式
import './assets/style/reset.css';
// Element UI
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// 富文本编辑器
import VueQuillEditor from 'vue-quill-editor';
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';

// 为了修复表格因为滚动条高度占用的问题
import '@/styles/fixed_table_scrollbar_height.css';

// 允许使用Vue开发者工具
Vue.config.devtools = true;
// Vue.config.silent = true;
Vue.use(VueQuillEditor);
window._AMapSecurityConfig = {
    securityJsCode: '72f6654883f0e66139fbeeb52cbfbf69' // 开发环境使用
};
// 自定义指令
import refHeight from '@/directive/ref-height.js';
Vue.use(refHeight);

// 导入图片鉴权指令
import auth from '@/directive/img-auth';
Vue.directive('img-auth', auth);

Vue.use(ElementUI, { size: "medium" });
ElementUI.Table.props.headerCellStyle.default = () => {
    return {
      backgroundColor: '#F8F8F9',
      color: '#606266',
      borderRight: '1px solid #EBEEF5'
    }
  }
Vue.use(SlideVerify);
Vue.config.productionTip = false;
Vue.use(VueLazyload, {
    error: require('./assets/img-error.png'),
    loading: require('./assets/loading2.gif')
});
Vue.use(ViewUI, {
    i18n: (key, value) => i18n.t(key, value)
});
Vue.use(VueClipboard);
Vue.use(hasPermission);
Vue.use(hasRole);
Vue.use(iviewArea);
Vue.use(XIcon);
Vue.use(VueApexCharts);
Vue.component('apexchart', VueApexCharts);
// 挂载全局使用的方法
Vue.prototype.getRequest = getRequest;
Vue.prototype.postRequest = postRequest;
Vue.prototype.putRequest = putRequest;
Vue.prototype.postBodyRequest = postBodyRequest;
Vue.prototype.getNoAuthRequest = getNoAuthRequest;
Vue.prototype.postNoAuthRequest = postNoAuthRequest;
Vue.prototype.importRequest = importRequest;
Vue.prototype.setStore = setStore;
Vue.prototype.getStore = getStore;
Vue.prototype.removeStore = removeStore;
Vue.prototype.format = format;
Vue.prototype.hasPermission = hasPerm;
Vue.prototype.hasRole = hasR;
Vue.prototype.restTableCellWidth = onRestTableCellWidth
Vue.prototype.searchLabelWidth = onRestsearchLabelWidth
Vue.prototype.restTreeTableCellWidth = onRestTreeTableCellWidth
// Define a global variable in Vue 2
Vue.prototype.$backColor = '#f8f8f9';
// 引入自适应布局插件
// import 'amfe-flexible';
import { TaskNode } from 'vue-task-node';
import 'vue-task-node/dist/css/vnode.css';
import './assets/iconfont/iconfont.css';
Vue.use(TaskNode);

//初始化样式
import './assets/style/reset.css';

import { setDialogBox } from '@/libs/common';

window.setDialogBox = setDialogBox;

import { initDict } from '@/libs/common';

// 判断是否是build 开发阶段注释掉 上线后请开启
if (process.env.NODE_ENV === 'production') {
    Vue.config.devtools = false;
    Vue.config.debug = false;
    Vue.config.silent = true;

    // 全局禁用console.log 以防止潜在的信息泄露及内存泄漏
    window.oldConsole = console;

    window.console = new Proxy(console, {
        get: function(target, prop) {
            if (prop === 'log') {
                if (window.disableConsole) {
                    return function() {};
                } else {
                    window.disableConsole = true;
                    console.info('全局禁用log');
                    return function() {};
                }
            }
            return target[prop];
        }
    });
}


/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    store,
    i18n,
    render: h => h(App),
    data: {},
    mounted() {
        initDict(this);
        // 加载主题
        this.$store.commit('setTheme', sessionStorage.theme);
        // 初始化菜单
        util.initRouter(this);
        // 设置用户信息
        this.$store.commit('setUserInfo', {
            nickname: sessionStorage.nickname,
            avatar: sessionStorage.avatar
        });
        // 显示打开的页面的列表
        this.$store.commit('setOpenedList');
        this.$store.commit('initCachepage');
    }
});
